﻿#include "formadvancedsearch.h"
#include "ui_formadvancedsearch.h"
#include "workorder.h"
#include <QMessageBox>
#include <QDebug>

FormAdvancedSearch::FormAdvancedSearch(QWidget *parent)
    : QWidget(parent)
    , ui(new Ui::FormAdvancedSearch)
{
    this->hide();
    ui->setupUi(this);

    model=new QStandardItemModel(this);
    ui->listView->setModel(model);
    ui->listView->setEditTriggers(QAbstractItemView::NoEditTriggers);
}

FormAdvancedSearch::~FormAdvancedSearch()
{
    delete ui;
}

void FormAdvancedSearch::on_listView_doubleClicked(const QModelIndex &index)
{
    emit slot_switch_combox(model->item(index.row())->text(), ui->lineEdit->text());
}

void FormAdvancedSearch::on_lineEdit_textChanged(const QString &arg1)
{
    model->clear();
    if(arg1.isEmpty()){return;}
    WorkOrder workOrder;
    QStringList str_list=workOrder.getWorkList();
    QMutableStringListIterator i(str_list);
    while (i.hasNext()) {
        QString str=i.next();
        workOrder.setWorkPath(str);
        if (!workOrder.isInWorkOrder(arg1)) {
            i.remove();
        }else{
            model->appendRow(new QStandardItem(str));
        }
    }
}

